﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CommonGameClasses;

namespace BattleLogic
{
	public class Hud: IHud
	{
		private DateTime lastAdd;
		private const string systemId = "SYSTEM:";

		public List<string> ListMessages { get; set; }

		public Hud()
		{
			this.lastAdd = DateTime.Now;
		}

		public void AddMessage(string message)
		{
			this.AddMessage(message, false);
		}

		public void AddMessage(string message, bool system)
		{
			this.lastAdd = DateTime.Now;
			string[] messageList = message.Split(new string[]{Environment.NewLine}, StringSplitOptions.None);

			foreach (string msg in messageList)
			{
				ListMessages.Add(system == true ? String.Concat(systemId, msg) : msg);
			}
		}

		public void ClearMessage()
		{
			this.ListMessages.Clear();
		}

		public void Update()
		{
			if (this.ListMessages.Count > 0 && (DateTime.Now - lastAdd).TotalSeconds > 4)
			{
				lastAdd = DateTime.Now;
				this.ListMessages.RemoveAt(0);
			}

			while (this.ListMessages.Count > 10)
				this.ListMessages.RemoveAt(0);
		}
	}
}
